package com.woniu.sharepark.util;
import com.woniu.sharepark.common.pojo.UserInfo;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;


/** Md5加密util
 * @author DELL
 * @date 2019/6/4 11:52
 * version v1.0
 */

public class MD5Encoding {

    public static String lowerMD5(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            return new BigInteger(1, md.digest()).toString(16);
        } catch (Exception e) {
           e.printStackTrace();
           return null;
        }
    }


    public static String shortLowerMD5(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(str.getBytes());
            return new BigInteger(1, md.digest()).toString(16);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    public static String upperMD5(String s) {
        char hexDigits[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  
        try {
            byte[] btInput = s.getBytes();
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
    * 租车订单编号
    * @title createOrderNumber
    * @param userInfo
    * @return java.lang.String
    * @author DELL
    * @date 2019/6/19 17:13
    **/

    public static String createOrderNumber(UserInfo userInfo){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
         format = format.replaceAll("-","");
         format = format.replace(" ","");
         format = format.replaceAll(":","")+userInfo.getuId();
        return format;
    }

   public static String createWaterNumber(UserInfo userInfo,Double money){
        String myMoney = String.valueOf(money);
        if (myMoney.contains(".")){
            myMoney = myMoney.replace("."," ");
        }
        Date date = new Date();
       SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String format = simpleDateFormat.format(date);
       format = format.replaceAll("-","");
       format = format.replace(" ","");
       format = format.replaceAll(":","")+userInfo.getuId()+myMoney;

        return format;
   }


    public static void main(String[] args) {

	}
}
